/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pgentity.redis.hash;

import db.DBContext;
import db.RedisKey;
import java.util.concurrent.TimeUnit;

/**
 *
 * @author Salm
 */
public class ExpiredDataHash extends DataHash {
    private final int expireInSecs;

    public ExpiredDataHash(RedisKey rKey, long expire, TimeUnit unit) {
        super(rKey);
        
        this.expireInSecs = (int) TimeUnit.SECONDS.convert(expire, unit);
    }

    @Override
    public void incData(String dataID, int by) {
        DBContext.Redis().hincrbyENX(redisKey, dataID, by, expireInSecs);
    }

    @Override
    public void setData(String dataID, Object data) {
        DBContext.Redis().hsetENX(redisKey, dataID, dataID, expireInSecs);
    }
}
